package com.itkim.userinfo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.itkim.userinfo.domain.ItkimUser;
import com.itkim.userinfo.service.IItkimUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户信息Controller
 * 
 * @author itkim
 * @date 2024-06-02
 */
@Controller
@RequestMapping("/userinfo/manage")
public class ItkimUserController extends BaseController
{
    private String prefix = "userinfo/manage";

    @Autowired
    private IItkimUserService itkimUserService;

    @RequiresPermissions("userinfo:manage:view")
    @GetMapping()
    public String manage()
    {
        return prefix + "/manage";
    }

    /**
     * 查询用户信息列表
     */
    @RequiresPermissions("userinfo:manage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ItkimUser itkimUser)
    {
        startPage();
        List<ItkimUser> list = itkimUserService.selectItkimUserList(itkimUser);
        return getDataTable(list);
    }

    /**
     * 导出用户信息列表
     */
    @RequiresPermissions("userinfo:manage:export")
    @Log(title = "用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ItkimUser itkimUser)
    {
        List<ItkimUser> list = itkimUserService.selectItkimUserList(itkimUser);
        ExcelUtil<ItkimUser> util = new ExcelUtil<ItkimUser>(ItkimUser.class);
        return util.exportExcel(list, "用户信息数据");
    }

    /**
     * 新增用户信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户信息
     */
    @RequiresPermissions("userinfo:manage:add")
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ItkimUser itkimUser)
    {
        return toAjax(itkimUserService.insertItkimUser(itkimUser));
    }

    /**
     * 修改用户信息
     */
    @RequiresPermissions("userinfo:manage:edit")
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        ItkimUser itkimUser = itkimUserService.selectItkimUserByUserId(userId);
        mmap.put("itkimUser", itkimUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户信息
     */
    @RequiresPermissions("userinfo:manage:edit")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ItkimUser itkimUser)
    {
        return toAjax(itkimUserService.updateItkimUser(itkimUser));
    }

    /**
     * 删除用户信息
     */
    @RequiresPermissions("userinfo:manage:remove")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(itkimUserService.deleteItkimUserByUserIds(ids));
    }
}
